import { ApiProperty } from "@nestjs/swagger";

export class PageResultVO<T = any> {
    /**
     * 当前页
     */
    @ApiProperty({ example: 1, description: "当前页" })
    current: number;

    /**
     * 每页大小
     */
    @ApiProperty({ example: 15, description: "每页数量" })
    size: number;

    /**
     * 总数
     */
    @ApiProperty({ example: 100, description: "总数" })
    total: number;

    /**
     * 总页数
     */
    @ApiProperty({ example: 10, description: "总页数" })
    pages: number;

    /**
     * 数据
     */
    @ApiProperty({ description: "数据列表", isArray: true })
    list: T[];

    /**
     * 扩展字段
     * 用于存放一些不常用的字段
     * 例如：分页查询时，返回的其他信息
     * 例如：导出数据时，返回的其他信息
     * 例如：其他业务需要的字段
     */
    @ApiProperty({ description: "扩展字段" })
    extend: Record<string, any>;

    constructor(list: T[], total: number, pages: number, current: number, size: number, extend?: Record<string, any>) {
        this.current = current;
        this.size = size;
        this.total = total;
        this.pages = pages;
        this.list = list;
        this.extend = extend ?? {};
    }
}
